<!--suppress ALL -->
<div class="layui-fluid layui-anim website-anim" id="website-declareEntrust" lay-title="过程管理"
     xmlns:th="http://www.w3.org/1999/xhtml">
    <div class="layui-row website-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body website-table-full">
                    <form class="layui-form layui-table-form" lay-filter="declareEntrust-table-form">
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">课题名称</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="name" autocomplete="off" class="layui-input"
                                                   placeholder="请输入课题名称">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">选题名称</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="topicName" autocomplete="off" class="layui-input"
                                                   placeholder="请输入课题名称">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">学科分类</label>
                                        <div class="layui-input-inline">
                                            <select name="subjectTypeCode">
                                                <option value="">请选择</option>
                                                <option
                                                        th:each="item : ${subjectTypes}"
                                                        th:value="${item.code}" th:text="${item.name}">
                                                </option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">主持人</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="leaderName" autocomplete="off" class="layui-input"
                                                   placeholder="请输入主持人">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary website-button-blue-plain table-action"
                                     id="query">
                                    查询
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary website-button-green-plain table-action"
                                     id="reset">
                                    重置
                                </div>
                            </div>
                        </div>
                    </form>
                    <table lay-filter="declareEntrustTable" lay-data="{id: 'declareEntrustTable'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<!--表格中字典的显示-->
<script type="text/html" id="subjectType">
    {{#
    var dict=layui.dict.getByCode(d.subjectTypeCode);
    }}
    {{#  if(dict){ }}
    <span>{{ dict.name }}</span>
    {{#  } }}
</script>
<script type="text/html" id="examineType">
    {{#
    var dict=layui.dict.getByCode(d.examine);
    }}
    {{#  if(dict){ }}
    <span>{{ dict.name }}</span>
    {{#  } }}
</script>
<!--表格中的操作栏-->
<script type="text/html" id="declareEntrust-option">
    {{# if(d.examine=='info_wait'){}}
    <a lay-event="check" shiro:hasPermission="declareEntrust:checkInfo" class="website-blue">审核</a>
    {{# } if((d.examine=='info_passed'||d.examine=='conclude_failed') && d.examineDelay=='delay_wait') { }}
    <a lay-event="checkDelay" shiro:hasPermission="declareEntrust:checkDelay" class="website-blue">延期</a>
    {{# } if((d.examine=='info_passed'||d.examine=='conclude_failed') && d.examineChange=='change_wait') { }}
    <a lay-event="checkChange" shiro:hasPermission="declareEntrust:checkChange" class="website-blue">变更</a>
    {{# } }}
    <a lay-event="detail" shiro:hasPermission="declareEntrust:list" class="website-green">详情</a>
</script>

<script data-th-inline="none" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'form', 'table', 'website', 'dict', 'laydate'], function () {
        var $ = layui.jquery,
                website = layui.website,
                form = layui.form,
                table = layui.table,
                dict = layui.dict,
                laydate = layui.laydate,
                dropdown = layui.dropdown,
            $view = $('#website-declareEntrust'),
            $query = $view.find('#query'),
            $reset = $view.find('#reset'),
            $searchForm = $view.find('form'),
                sortObject = {field: 'createTime', type: null},
                tableIns,
                createTimeFrom,
                createTimeTo;
        form.render();
        initTable();


        /**
         * table操作栏的按钮监听事件
         **/
        table.on('tool(declareEntrustTable)', function (obj) {
            var data = obj.data,
                    layEvent = obj.event;
            if (layEvent === 'detail') {
                /*website.modal.open('信息审核','biz/declareEntrust/qualificationDetail/' + data.declareId, {
                    btn: ['关闭'],
                    area: $(window).width() <= 750 ? '95%' : '70%',
                    offset: '30px',
                    yes: function (index, layero) {
                        layer.closeAll();
                    },
                });*/
                website.modal.view('信息详情', 'biz/declareEntrust/qualificationDetail/' + data.declareId, {
                    area: $(window).width() <= 750 ? '95%' : '80%'
                });
               //website.navigate('/biz/declareEntrust/qualificationDetail/' + data.declareId);
            }

            if (layEvent === 'check') {
                website.modal.view('信息审核', 'biz/declareEntrust/check/' + data.declareId, {
                    area: $(window).width() <= 750 ? '95%' : '50%'
                });
            }
            if (layEvent === 'checkChange') {
                website.modal.view('信息变更审查', 'biz/declareEntrust/checkChange/' + data.declareId, {
                    area: $(window).width() <= 750 ? '95%' : '80%'
                });
            }
            if (layEvent === 'checkDelay') {
                website.modal.view('延期审查', 'biz/declareEntrust/checkDelay/' + data.declareId, {
                    area: $(window).width() <= 750 ? '95%' : '50%'
                });
            }
        });

        /**
         * 表格的排序点击
         **/
        table.on('sort(declareEntrustTable)', function (obj) {
            sortObject = obj;
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });

            $query.on('click', function () {
        var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
        tableIns.reload({where: params, page: {curr: 1}});
        });
            $reset.on('click', function () {
            $searchForm[0].reset();
        sortObject.type = 'null';
        createTimeTo = null;
        createTimeFrom = null;
        tableIns.reload({where: getQueryParams(), page: {curr: 1}, initSort: sortObject});
        });
        /**
         * 初始化表格
         */
        function initTable() {
            tableIns = website.table.init({
                elem: $view.find('table'),
                id: 'declareEntrustTable',
                url: ctx + 'declareEntrust/list',
                cols: [[
                    { type: 'numbers', title: '序号'},
                    {field: 'itemCode', title: '立项编号', minWidth: 100},
                    {field: 'name', title: '课题名称', minWidth: 100},
                    {title: '学科分类', templet: '#subjectType', minWidth: 60},
                    {field: 'topicName', title: '选题名称', minWidth: 100},
                    {title: '信息审核状态', templet: '#examineType', minWidth: 100},
                    {field: 'topicUnitName', title: '课题组织单位', minWidth: 100},
                    {field: 'initiatorName', title: '牵头人姓名', minWidth: 100},
                    {field: 'leaderName', title: '主持人姓名',minWidth: 100},
                    {field: 'mobile', title: '主持人手机',minWidth: 100},
                    {title: '操作', align:'center',toolbar: '#declareEntrust-option', minWidth: 250}
                ]]
            });
        }
        /**
         * 获取查询条件
         * @returns {{}}
         */
        function getQueryParams() {
            var params = $searchForm.serializeJson();
            return params;
        }
    })
</script>